package model

import (
	"errors"
	"time"
)

type Exam struct {
	Id          int64
	Uid         int64
	Pid         int64
	Name        string
	CreatedAt   time.Time `xorm:"created"`
	PassScore   int32
	Score       float32
	UserAnswers map[int64]string
	Duration    int32
}

func (e *Exam) OneById() error {
	ok, err := orm.ID(e.Id).Get(e)
	if !ok {
		return errors.New(ExamNotFound)
	}
	return err
}

func (e *Exam) Create() error {
	ok, err := orm.Insert(e)
	if ok == 0 {
		return errors.New(ExamCreateFailed)
	}
	return err
}
